Add 'encrypt' option to text, html outputs to keep the hint at least a little secret.
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 16 Apr 2004 15:37:30 +0000 (15:37 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 16 Apr 2004 15:37:30 +0000 (15:37 +0000)
gpsbabel/defs.h
gpsbabel/html.c
gpsbabel/text.c
gpsbabel/util.c

index d08d711464cb063d7c7e37ec8c653e60e62270a5..50e540fe86b94eb340bab5d824ebe808d1eae68e 100644 (file)
@@ -422,6 +422,8 @@ char * strip_nastyhtml(const char * in);
 char * str_utf8_to_cp1252( const char * str );
 char * str_utf8_to_ascii( const char * str );
 
+char * rot13( const char *str );
+
 /*
  * PalmOS records like fixed-point numbers, which should be rounded
  * to deal with possible floating-point representation errors.
index 8a128bb5ce846cafa608d7a6f0d101a01dffe9c7..8b32e5448895934af129a38662864f2fe4d2268d 100644 (file)
@@ -28,6 +28,7 @@ static FILE *file_out;
 static void *mkshort_handle;
 
 static char *stylesheet = NULL;
+static char *encrypt = NULL;
 
 #define MYNAME "HTML"
 
@@ -35,6 +36,8 @@ static
 arglist_t html_args[] = {
        { "stylesheet", &stylesheet, 
                "Path to HTML style sheet", ARGTYPE_STRING },
+       { "encrypt", &encrypt,
+               "Encrypt hints using ROT13", ARGTYPE_BOOL },
        {0, 0, 0, 0}
 };
 
@@ -104,7 +107,13 @@ html_disp(const waypoint *wpt)
                        fprintf (file_out, "<p class=\"desclong\">%s</p>\n", strip_nastyhtml(wpt->gc_data.desc_long.utfstring));
                        }
                if (wpt->gc_data.hint) {
-                       fprintf (file_out, "<p class=\"hint\"><strong>Hint:</strong> %s</p>\n", wpt->gc_data.hint);
+                       char *hint = NULL;
+                       if ( encrypt )
+                               hint = rot13( wpt->gc_data.hint );
+                       else 
+                               hint = xstrdup( wpt->gc_data.hint );
+                       fprintf (file_out, "<p class=\"hint\"><strong>Hint:</strong> %s</p>\n", hint);
+                       xfree( hint );
                }
        }
        else if (strcmp(wpt->notes,wpt->description)) {
index cebd5a8358aaa3d9d678b7a27ff670b647093203..180a9b977f5136711eb2968db7e603b0907ab9b1 100644 (file)
@@ -28,6 +28,7 @@ static FILE *file_out;
 static void *mkshort_handle;
 
 static char *suppresssep = NULL;
+static char *encrypt = NULL;
 
 #define MYNAME "TEXT"
 
@@ -35,6 +36,8 @@ static
 arglist_t text_args[] = {
        { "nosep", &suppresssep, 
                "Suppress separator lines between waypoints", ARGTYPE_BOOL },
+       { "encrypt", &encrypt,
+               "Encrypt hints using ROT13", ARGTYPE_BOOL },
        {0, 0, 0, 0}
 };
 
@@ -97,7 +100,13 @@ text_disp(const waypoint *wpt)
                        xfree(stripped_html);
                        }
                if (wpt->gc_data.hint) {
-                       fprintf (file_out, "\nHint: %s\n", wpt->gc_data.hint);
+                       char *hint = NULL;
+                       if ( encrypt ) 
+                               hint = rot13( wpt->gc_data.hint );
+                       else
+                               hint = xstrdup( wpt->gc_data.hint );
+                       fprintf (file_out, "\nHint: %s\n", hint);
+                       xfree( hint );
                }
        }
        else if (strcmp(wpt->notes,wpt->description)) {
index 010684d8a3a827804be2eb45a841daf51835ac79..0d3505c9ff878e5e28ff1f38875b96e06a36fa36 100644 (file)
@@ -628,7 +628,29 @@ strsub(char *s, char *search, char *replace)
        strcat(d, p + slen);
        return d;
 }
-                       
+
+char *
+rot13( const char *s )
+{
+       char *result = xstrdup( s );
+       char *cur = result;
+       int flip = 1;
+       while (cur && *cur ) {
+               if ( flip ) {
+                       if (*cur == '[') flip = 0;
+                       else if ( *cur >= 'A' && *cur <= 'Z' ) {
+                               *cur = 'A' + ((*cur-'A')+13)%26;
+                       }
+                       else if ( *cur >= 'a' && *cur <= 'z' ) {
+                               *cur = 'a' + ((*cur-'a')+13)%26;
+                       }
+               }
+               else if ( *cur == ']' ) flip = 1;
+               cur++;
+       }
+       return result;
+}
+
 void utf8_to_int( const char *cp, int *bytes, int *value ) 
 {
        if ( (*cp & 0xe0) == 0xc0 ) {